package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {

	r := gin.Default()
	//posts 推文/帖子
	// restfull 风格: GET/POST/PUT/DELETE
	r.GET("/posts", func(c *gin.Context) {
		c.String(http.StatusOK, "GET")
	})
	r.POST("/posts", func(c *gin.Context) {
		c.String(http.StatusOK, "POST")
	})
	//根据 id 修改一篇推文
	//取路径上的值作为请求的入参
	r.PUT("/posts/:id", func(c *gin.Context) {
		//返回入参中的 id
		c.String(http.StatusOK, fmt.Sprintf("PUT id: %s", c.Param("id")))
	})
	r.DELETE("/posts", func(c *gin.Context) {
		c.String(http.StatusOK, "DELETE")
	})
	//匹配所有的请求方法
	r.Any("users", func(c *gin.Context) {
		c.String(http.StatusOK, "any")
	})

	r.Run()
}
